package com.ozy.kxreader.base

import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.LifecycleOwner
import io.reactivex.disposables.CompositeDisposable

/**
 * Created by 欧源 on 2018/1/30.
 */
open class BasePresenter<M : IModel, V : IView> : IPresenter, LifecycleObserver {

    protected var mCompositeDisposable: CompositeDisposable? = null
    protected var mModel: M
    protected var mRootView: V

    constructor(model: M, rootView: V) {
        this.mModel = model
        this.mRootView = rootView
        onStart()
    }

    override fun onStart() {
        if (mRootView != null && mRootView is LifecycleOwner) {
            (mRootView as LifecycleOwner).lifecycle.addObserver(this)
            if (mModel != null && mModel is LifecycleObserver) {
                (mRootView as LifecycleOwner).lifecycle.addObserver(mModel as LifecycleObserver?)
            }
        }
    }

}